<?php


namespace app\api\controller;

use app\api\model\Member;

class Base
{
    public function register()
    {

        $mobile = input('get.mobile');//接收GET键名为name的值并且赋给变量name
        $password = input('get.password');
        $nickname = input('get.nickname');
        if (empty($mobile))output_error('手机号不能为空');
        if (empty($password))output_error('密码不能为空');
        if (empty($nickname))output_error('昵称不能为空');
        if (strlen($mobile)!=11)output_error('手机号码格式不正确');
        if(Member::register($mobile,$password,$nickname)) output_data('注册成功');
        output_error('注册失败，请检查提交的数据');
    }
    public function login()
    {
        $mobile = input('get.mobile');
        $password = input('get.password');
        $model = input('grt.model');
        if (empty($mobile))output_error('手机号不能为空');
        if (empty($password))output_error('密码不能为空');
        if (empty($model))output_error('密码不能为空');

        $condition = array();
        $condition[] = ['member_mobile','=',$mobile];
        $condition[] = ['member_password','=',md5($password)];
        $member = Member::where($condition)->find();
        if (empty($member))output_error('账号密码错误');
        $token =md5($member['memder_id'] . time());
        $data = array();
        $data['memder_id'] = $member['memder_id'];
        $data['token_content'] = $token;
        $data['device_model'] = $model;
        $data['end_time'] = time() + 65535;
        $data['add_time'] = time();
        echo Member::getLastSql();
        output_data($token);
    }
}
